How do you move a file to another directory?
How do you move a file to another directory?
Ravi Vishwakarma is a dedicated Software Developer with a passion for crafting efficient and innovative solutions. With a keen eye for detail and years of experience, he excels in developing robust software systems that meet client needs. His expertise spans across multiple programming languages and technologies, making him a valuable asset in any software development project.
Anubhav Kumar
19-May-2025In C#, you can move a file to another directory using the
File.Movemethod from theSystem.IOnamespace.Syntax:
sourceFileName: Full path of the file you want to move.destFileName: Full path where you want the file moved.Example:
This moves
file.txtfromC:\sourcetoC:\destination.Important Notes:
IOExceptionis thrown. There’s no built-inoverwriteoption forFile.Move, so you'd have to delete the destination file first if needed.DirectoryNotFoundExceptionis thrown.Optional: Overwrite manually if needed